Skip to content

feat(optimizer): integrate EmoSens v3.9.1 optimizer#67

Merged
wochenlong merged 5 commits into
wochenlong:mainfrom
777441:main
Jun 3, 2026
Merged

feat(optimizer): integrate EmoSens v3.9.1 optimizer#67
wochenlong merged 5 commits into
wochenlong:mainfrom
777441:main

Conversation

@777441
Copy link
Copy Markdown

@777441 777441 commented Jun 1, 2026

概述

集成 EmoSens v3.9.1 优化器。

变更内容

  • 新增文件vendor/sd-scripts/library/optimizers/emosens.py — EmoSens 优化器实现(Apache 2.0)
  • 修改vendor/sd-scripts/library/train_util.py — 在 get_optimizer() 的 Automagic 分支后注册 EmoSens
  • 修改mikazuki/schema/shared.ts — LR_OPTIMIZER / ANIMA_FAST_LR_OPTIMIZER dropdown 添加选项
  • 修改mikazuki/schema/anima-finetune.ts — finetune dropdown 添加选项
  • 修改NOTICE.md — 添加了EmoSens(Apache 2.0) 的归属声明

归属与许可

  • EmoSens 原作者:[muooon],Apache 2.0 许可
  • 已在 NOTICE.md 中添加完整归属条目

注册方式

遵循 get_optimizer() 中 Automagic 的注册模式:

  1. train_util.py 中添加 elif 分支
  2. schema dropdown 中添加选项(Automagic 之后)

自测情况

  • Anima LoRA 训练正常完成。
  • 仅测试了搭配constant调度器下的使用,在loss值到达代码中指定的loss值后控制台会有提醒。

--- 本次代码均由Claude code接入mimo2.5pro完成

  • Add EmoSens optimizer (Apache 2.0) with lazy ECC patching (backward hook attached at instantiation, no side-effect on other optimizers)
  • Register EmoSens in get_optimizer() after Automagic branch in train_util.py
  • Add EmoSens to LR_OPTIMIZER and ANIMA_FAST_LR_OPTIMIZER dropdowns in shared.ts
  • Add EmoSens to finetune optimizer dropdown in anima-finetune.ts
  • Add EmoSens Apache 2.0 attribution with DOI reference in NOTICE.md

- Add EmoSens optimizer (Apache 2.0) with lazy ECC patching
  (backward hook attached at instantiation, no side-effect on other optimizers)
- Register EmoSens in get_optimizer() after Automagic branch in train_util.py
- Add EmoSens to LR_OPTIMIZER and ANIMA_FAST_LR_OPTIMIZER dropdowns in shared.ts
- Add EmoSens to finetune optimizer dropdown in anima-finetune.ts
- Add EmoSens Apache 2.0 attribution with DOI reference in NOTICE.md
@wochenlong
Copy link
Copy Markdown
Owner

感谢贡献!整体集成方式清晰,和本仓库现有 Automagic 的模式一致,方向是对的 👍

可以的部分(合并方向 OK)

  • �endor/sd-scripts/library/optimizers/emosens.py + rain_util.py 注册:Kohya / Anima 全量微调等走 get_optimizer() 的训练链路会生效,放在 Automagic 后是约定写法,没有技术依赖问题。
  • NOTICE.md 归属:Apache 2.0 来源、链接与说明完整,符合仓库要求。
  • shared.ts / �nima-finetune.ts 下拉:Kohya LoRA、Anima Finetune 侧加选项合理;schema 由后端加载,不必改 rontend/dist。
  • 自测说明:Anima LoRA + constant 调度能跑通,对 review 很有帮助。

合并前希望补全的部分

  1. Anima Fast 下拉请先去掉 EmoSens(或整段 Fast optimizer 不加)
    Fast 模式实际跑的是 extensions/anima_lora 上游的 rain.py,不会走本 PR 改的 �endor/sd-scripts/train_util.py;且 mikazuki/anima_fast_backend/adapter.py 的 FAST_SUPPORTED_OPTIMIZERS 白名单里目前没有 EmoSens,用户选了会在开训前直接被拒绝。建议:Fast 页暂不提供该选项,等 Fast 插件侧真正支持后再加。

  2. 学习率说明 / 提示
    EmoSens 对 LoRA 推荐 lr≈1.0,而 UI 默认常为 1e-4。建议在 schema 描述或文档里注明「选用 EmoSens 时请把 learning_rate 调到约 1.0」,或在 adapter 里像 Automagic 一样加一条 warning,避免用户按默认 lr 训练效果偏差。

  3. (可选)optimizer_args_custom 说明
    stopcoef、
    otify 等参数若需自定义,可走现有 optimizer_args_custom;可在 PR 或简短文档里写一句,方便进阶用户。

  4. (可选)维护者冒烟
    合并后我们会在 main 上补一次 SD3 LoRA + Anima Finetune 的快速验证;若你方便也可再补一条非 constant 调度器的自测说明。


结论:核心实现可以合;请至少处理 第 1 点(Fast 下拉),第 2 点强烈建议一并改。改完后 @ 我或直接 push 到同一 PR,我们尽快 review 合并。再次感谢!

777441 and others added 2 commits June 2, 2026 10:13
…A lr hint

- Remove EmoSens from ANIMA_FAST_LR_OPTIMIZER (Fast mode routes through rain.py,
  not train_util.py; FAST_SUPPORTED_OPTIMIZERS does not include it)
- Remove EmoSens from anima-finetune optimizer list
- Add conditional description hint in LR_OPTIMIZER recommending lr≈1.0 for
  EmoSens (LoRA training)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@777441
Copy link
Copy Markdown
Author

777441 commented Jun 2, 2026

@wochenlong

自测环境与结果

本地环境

项目 详情
GPU AMD RX580
测试范围 最低启动与正常运行验证(单张空白图)
训练实测 未进行

云端环境

项目 详情
GPU H20
PyTorch 2.7.0(cuda12.8)
Attention Flash Attention 2
训练集 20 张
训练量 1 batch × 10 epoch(最低限度默认参数)

已通过的训练组合

网络 调度器 状态
LoRA constant
LoKr constant
T-LoRA constant
LoRA-FA linear
VeRA cosine
LoHa polynomial

以上组合均正常完成训练,未出现报错或中断。
LoRA-FA 训练曲线
linear
VeRA 训练曲线
cosine
LoHa 训练曲线
polynomial

@wochenlong
Copy link
Copy Markdown
Owner

感谢补充,这版整体已经很接近可以合并了。EmoSens 的主体实现、NOTICE 许可说明、普通训练侧接入看起来都 OK,自测信息也比较充分。

现在还差最后一点边界处理:Anima Fast 模式目前不走这次改的 vendor/sd-scripts/library/train_util.py,而且 FAST_SUPPORTED_OPTIMIZERS 里还没有 EmoSens。所以合并前需要明确一下 Fast 的支持策略:

  • 如果暂不支持 Fast,请确保 Fast 页不要暴露 EmoSens,或明确提示仅普通训练 / Anima Finetune 可用。
  • 如果要支持 Fast,请同步适配 extensions/anima_lora 训练侧,并补 FAST_SUPPORTED_OPTIMIZERS 和一个最小自测。

处理完这一点后,我这边就可以合并了。

@777441
Copy link
Copy Markdown
Author

777441 commented Jun 3, 2026

感谢补充,这版整体已经很接近可以合并了。EmoSens 的主体实现、NOTICE 许可说明、普通训练侧接入看起来都 OK,自测信息也比较充分。

现在还差最后一点边界处理:Anima Fast 模式目前不走这次改的 ,而且 里还没有 。所以合并前需要明确一下 Fast 的支持策略:vendor/sd-scripts/library/train_util.py``FAST_SUPPORTED_OPTIMIZERS``EmoSens

  • 如果暂不支持 Fast,请确保 Fast 页不要暴露 ,或明确提示仅普通训练 / Anima Finetune 可用。EmoSens
  • 如果要支持 Fast,请同步适配 训练侧,并补 和一个最小自测。extensions/anima_lora``FAST_SUPPORTED_OPTIMIZERS

处理完这一点后,我这边就可以合并了。

@wochenlong 由于能力有限加上token不够用,暂时不准备在Anima fast当中添加emosens。已经经过测试在快速模式中没有与emosens相关的代码。

wochenlong added a commit that referenced this pull request Jun 3, 2026
Regression guard after merging PR #67: Fast uses anima_lora train.py, not train_util EmoSens.

Co-authored-by: Cursor <cursoragent@cursor.com>
@wochenlong wochenlong merged commit f0a9cf8 into wochenlong:main Jun 3, 2026
@wochenlong
Copy link
Copy Markdown
Owner

已确认:Anima Fast 暂不提供 EmoSens 的策略可以接受,与维护者预期一致。

核对结果(27deec7):

  • LR_OPTIMIZER 含 EmoSens,并附带 lr≈1.0 的条件说明
  • ANIMA_FAST_LR_OPTIMIZER 不含 EmoSens
  • FAST_SUPPORTED_OPTIMIZERS 白名单 不含 EmoSens

已在 main 合并本 PR,并补充静态测试,防止日后误把 EmoSens 加回 Fast 下拉。

适用范围:Kohya / SD3 LoRA 等走 vendor/sd-scripts get_optimizer() 的训练路径;Fast 仍走 extensions/anima_lora,待插件侧支持后再单独开 PR。

感谢贡献与自测说明。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants